<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul {
      list-style: none;
      display: flex;
    }

    li {
      margin-left: 15px;
    }

    .active {
      background-color: skyblue;
    }

    
  </style>
</head>

<body>

  <div id="box">
    {{text}}
    <br>
    <!--v-bind绑定样式 -->
    <!--使用数组的方式动态控制样式,数组每一项对应每一个样式-->
    <p :class="['abc',flag?active:'','color',asd]">我是数组动态控制样式</p>
    <!--使用对象的方式控制,属性名为样式名,值为真表示有,值为假表示无-->
    <p :class="{'abc':true,'DNF':true,'LOL':true}">我是对象动态控制样式</p>




    数组写法
    <ul>
      <li @click="activeindex=item" :class="['abc',item===activeindex?'active':'']" v-for="item in 4">这是第{{item}}个li
        
      </li>
    </ul>

    对象写法
    <ul>
      <li @click="activeindex=item" :class="{active:activeindex==item,aa:true}" v-for="item in 4">这是第{{item}}个li
      </li>
    </ul>

    对象抽离写法
    <ul>
      <li @click="activeindex=item" :class="{active:activeindex==item ,...obj}" v-for="item in 4">这是第{{item}}个li
      </li>
    </ul>






  </div>

  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>
  <script>


    new Vue({
      el: '#box',
      data: {
        text: 'hello Vue',
        active: 'active',
        abc: '',
        flag: false,
        activeindex: 1,
        obj: { await: true }
      },

    })




  </script>

</body>

</html>